<!DOCTYPE html>
<html lang="en">
    <head>
        <meta http-equiv="x-ua-compatible" content="ie=edge">
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no" >
        <title>支付</title>
        <link rel="stylesheet" href="cash-in.css">
    </head>
    <body>
        <style>
            body{
                margin:0;
            }
        </style>
        <header>
            <img onclick="history.back(0)" src="../public_img/return.png" alt="返回">
            <p>提现页面</p>
        </header>
        <section>
            <ul>
                <li class="how-much-money">
                    <span>提现金额:</span>
                    <input class="much" type="text" placeholder="请输入提现金额" /><strong>元</strong>
                </li>
                <li>
                    <form>
                        <label>
                            <span>支付宝</span>
                            <input type="radio" value="alipay" name="radio1"><i></i>
                        </label>

                    </form>
                </li>
            </ul>
        </section>
        <footer>
            <button class="btn_comfirm">立即提现</button>
        </footer>
        <script src="../jquery.min.js"></script>
        <script src="../jquery.min.js"></script>
        <script src="../layer.js"></script>
        <script>
            $(function () {

                var money=localStorage.money;
                var wechat=localStorage.wechat;
                var alipay=localStorage.alipay;
                var alipay_name=localStorage.alipay_name;
                var way='';
                var cash='';
                var token=localStorage.phone;
                $('.btn_comfirm').on('click', function () {
                    console.log(alipay)
                    if(alipay==''){
                        layer.msg('请先绑定账户');
                        setInterval( function () {
                            window.location.href='../pricing/pay.html';
                        },1500)
                        return false;
                    }

                    cash=$('.much').val();
                    $('input:radio[name=radio1]').each(function () {
                        if($(this).prop('checked')){
                            way=$(this).val();
                        }
                    });
                    if(cash!='' && cash>0){

                        if(way=='wechat' && wechat!=''){
                            layer.msg('暂不支持微信');
                            //					if(money-cash>=0){
                            //						$.ajax({
                            //							url: localStorage.icandriveUrl+'api/cash.php',
                            //							type:'post',
                            //							dataType:'json',
                            //							data:{token:token,cash:cash,way:way},
                            //							success: function (data) {
                            //								if(data.status==200){
                            //									layer.msg('提现成功');
                            //									localStorage.removeItem('money');
                            //									localStorage.removeItem('wechat');
                            //									localStorage.removeItem('alipay');
                            //									setInterval( function () {
                            //										window.location.href='../cash/cash.html';
                            //									},1500)
                            //
                            //
                            //								}
                            //								else{
                            //									layer.msg('失败');
                            //								}
                            //							},
                            //							error: function () {
                            //								layer.msg('系统繁忙');
                            //							}
                            //						})
                            //					}else{
                            //
                            //						layer.msg('余额不足');
                            //					}
                        }
                        else if(way=='alipay'){
                            if(money-cash>=0){
                                $.ajax({
                                    url: 'https://newapp.icandrive.cn/api/cash.php',
                                    type:'post',
                                    dataType:'json',
                                    data:{token:token,cash:cash,way:way,account:alipay},
                                    success: function (data) {
                                        if(data.status==200){
                                            layer.msg('提现成功');
                                            localStorage.removeItem('money');
                                            localStorage.removeItem('wechat');
                                            localStorage.removeItem('alipay');
                                            setInterval(function () {
                                                window.location.href='../cash/cash.html';
                                            },1500)

                                        }
                                        else{
                                             layer.msg('系统维护中',function(){
                                history.go(0)
                            },1000);
                                        }
                                    },
                                    error: function () {
                                        layer.msg('系统繁忙');
                                    }
                                })
                            }
                            else{
                                layer.msg('余额不足');
                            }
                        }
                        else{
                            layer.msg('请选择提现方式');
                        }
                    }
                    else{
                        layer.msg('请选择正确的提现金额');
                    }



                })
            })
        </script>

        <script>
            document.addEventListener("plusready", function() {
                // 注册返回按键事件
                plus.key.addEventListener('backbutton', function() {
                    window.history.back();
                }, false);
                //此处false代表不退出页面，如果为true回退到上一个一面
            });
        </script>
    </body>
</html>
